package com.maggie.measure.bytecode.javassist.adapter;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 增强接口
 *
 * @author zyc
 * @date 2021-10-10 14:46:52
 */
public interface Advice {

    /**
     * 前置增强
     *
     * @param args
     * @param obj
     * @param method
     * @return
     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    default Object before(Object[] args, Object obj, Method method) throws InvocationTargetException, IllegalAccessException {
        return method.invoke(obj, args);
    }

    /**
     * 后置增强
     *
     * @param args
     * @param method
     * @param startTimeMs
     */
    default void after(Object[] args, Method method, long startTimeMs){
    }

    /**
     * 异常增强
     *
     * @param args
     * @param obj
     * @param method
     * @param e
     * @return
     */
    default Object exception(Object[] args, Object obj, Method method, Exception e) throws Exception {
        throw e;
    }
}
